package com.codejam2013.round1a;


import java.io.File;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;

public class A {

	static final String filein = "A-in.txt";
	static final String fileout = "A-out.txt";
	static int nTest;
	static BigInteger r, t;
	static final BigInteger two = new BigInteger("2");
	static final BigInteger four = new BigInteger("4");
	static final BigInteger eight = new BigInteger("8");
	
	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(new File(filein));
		PrintStream ps = new PrintStream(new File(fileout));
		PrintStream stdout = System.out;
		System.setOut(ps);
		nTest = scanner.nextInt();
		for (int test=1;test<=nTest;++test) {
			r = scanner.nextBigInteger();
			t = scanner.nextBigInteger();
			BigInteger r2_1 = two.multiply(r).subtract(BigInteger.ONE);
			BigInteger t8 = t.multiply(eight);
			BigInteger temp = r2_1.multiply(r2_1).add(t8);
			int ndig = temp.toString().length();
			int from, to;
			if (ndig % 2 == 0) {
				from = (ndig/2) - 1;
			}
			else {
				from = ndig/2;
			}
			to = from + 1;
			BigInteger low = new BigInteger((long)Math.pow(10, (double)from) + "");
			BigInteger high = new BigInteger((long)Math.pow(10, (double)to) + "");
			BigInteger sqrt = iSqrt(low, high, temp);
			BigInteger n = BigInteger.ZERO.subtract(r2_1).add(sqrt).divide(four);
			
			System.out.println("Case #" + test + ": " + n);
		}
	}
	
	public static BigInteger iSqrt(BigInteger low, BigInteger high, BigInteger num) {
		while (low.compareTo(high) <= 0) {
			BigInteger mid = low.add(high).divide(two);
			if (mid.multiply(mid).compareTo(num) > 0) {
				high = mid.subtract(BigInteger.ONE);
			}
			else if (mid.multiply(mid).compareTo(num) < 0) {
				BigInteger next = mid.add(BigInteger.ONE);
				int temp = next.multiply(next).compareTo(num);
				if (temp == 0) {
					return next;
				}
				else if (temp > 0) {
					return mid;
				}
				else {
					low = mid.add(BigInteger.ONE);
				}
			}
			else {
				return mid;
			}
		}
		return null;
	}

}
